package com.xin.spring.project.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * 数据库配置
 *
 * @author xinyue
 */
public class DruidUtil {

    private final DataSource source;
    private DruidUtil() throws Exception {
        Properties pros=new Properties();
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("druid.properties");
        pros.load(is);
        source = DruidDataSourceFactory.createDataSource(pros);
    }

    private static DruidUtil druidUtil;

    static {
        try {
            druidUtil = new DruidUtil();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static DruidUtil getInstance(){
        return druidUtil;
    }

    public Connection getConnection() throws Exception {
        return source.getConnection();
    }


}
